/**
 * Created by dashan on 2017/3/20.
 */
var mongoose = require('mongoose');

mongoose.connect('mongodb://dev1.bjvca.com:27017/test2');

var UserSchema = new mongoose.Schema({
    nickname:{
        type:String,
        trim:true
    },
    blog:{
        type:String,
        set:function(url){
            if(!url) return url;

            if(0 !== url.indexOf('http://') && 0 !==url.indexOf('https://'))
                url = 'http://'+url;

            return url;
        }
    }
});


UserSchema.set('toJson',{getter:true,virtual:true});
var User = mongoose.model('User',UserSchema);

var user = new User({
    nickname:" Sid ",
    blog:'chensd.com'
});

console.log('user:',user);
